import React from 'react';
import { Table, Row, Col, Form, Input, Icon, InputNumber, Radio, DatePicker, Select, Upload, Button, Switch, Modal, Popconfirm, Tabs, message, Tooltip } from 'antd';
const R = require('ramda');
import OperatorConstant from "../../../utils/OperatorConstant";
import BizParams from '../../../components/commons/BizParams'
import CurrencySelect from '../../../components/commons/CurrencySelect'
import IndustrySelect from '../../../components/commons/IndustrySelect'
import ManageSelect from '../../../components/commons/ManageSelect'
import Validator from '../../../utils/Validator'
import RightBox from "../../../components/commons/RightBox";
import PersonnelAllocation from '../components/PersonnelAllocation';
import moment from 'moment'
import RightContacts from "../../../utils/RightConstants";
import CurencyConstants from "../../../utils/CurencyConstants";
import Constants from "../../../utils/Constants";
const TabPane = Tabs.TabPane;
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const Option = Select.Option;
const csttype = ["普通客户", "会员客户"];


export default Form.create({ wrappedComponentRef: true })(class EditCustomer extends React.Component {

    constructor(props) {
        super(props);
        let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource

        this.state = {
            open: false,
            disabled: true,
            type: R.isNil(this.props.type) ? "" : this.props.type,
            ldData: {},
        };
    }

    handleResetFields = () => {
        if (this.personnelAllocation) this.personnelAllocation.handleResetFields();
        this.setState({ ldData: {} });
        setTimeout(this.props.form.resetFields, 1001);
    }


    checkAgencyagreementList = () => {
        return !R.isEmpty(this.props.agencyagreementList);
    }

    handleCustomer = () => {
        if (this.state.type == OperatorConstant.add) {
            return false;
        } else if (this.props.dataSource.csttype === '1') {
            return true;
        }
    }

    handleAddBlacklist = (id) => {
        let values = this.props.form.getFieldsValue();
        if (R.isEmpty(values.blacklistMemo)) {
            message.error("请输入黑名单备注！");
            return;
        }

        if (values.isblacklist) {
            message.error("此用户已经在黑名单中！");
            return;
        }
        this.props.dispatch({
            type: 'blacklist/addBlacklist',
            payload: {
                cstId: id,
                memo: values.blacklistMemo,
                onSuccess: () => {
                    this.props.dispatch({ type: 'customerManage/getCustomerById', payload: { id: id, isApproval: true } });
                },
                onFail: () => {
                    message.error("黑名单加入失败");
                }
            }
        })
    }

    handleUpdatePersonnel = () => {
        let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
        let values = this.props.form.getFieldsValue();

        if (R.isEmpty(values.manager) || R.isNil(values.manager)) {
            message.error("请选择业务经理！");
            return;
        }

        this.props.dispatch({
            type: "customerManage/updateCustomerBase",
            payload: {
                cstid: this.props.cstid,
                id: dataSource.id,
                manager: values.manager,
                onSuccess: () => {

                }


            }
        })
    }

    autoSync = () => {
        const { getFieldValue, setFieldsValue } = this.props.form;
        if (!getFieldValue('companyname')) {
            message.info("请先输入企业名称");
            return;
        }
        this.props.dispatch({
            type: "customerManage/autoSync",
            payload: {
                cstName: getFieldValue('companyname'),
                onSuccess: (ldData) => {
                    this.setState({ ldData });//缓存龙盾数据
                    setFieldsValue({ companynameen: ldData.engname, address: ldData.dom, recaddress: ldData.dom, url: ldData.website });//赋值
                    console.log(ldData);
                }
            }
        })
    }

    checkCustomerInfo = (dispatch, onSuccess, cstid, changeStatus) => {

        this.props.form.validateFields((errors, values) => {
            if (errors) {
                return;
            }

            let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource
            if (!this.checkAgencyagreementList() && this.state.type == "edit" && changeStatus === 2 && dataSource.csttype === "") { //提交审核才执行这个判断
                message.error("合作信息/代理协议列表为空，请检查");
                return;
            }

            let functionname = "";
            if (this.state.type == "add") {
                functionname = "createCustomer";

            } else if (this.state.type == "edit") {
                functionname = "updateCustomerBase";
            }

            let payload = {};
            payload.id = cstid;
            payload.companyname = values.companyname;
            payload.companynameen = values.companynameen;
            payload.shortname = values.shortname;
            payload.ischeckinfo = values.ischeckinfo;
            payload.companytype = values.companytype;
            payload.businessmodel = values.businessmodel;
            payload.telephone = values.telephone;
            payload.mobile = values.mobile;
            payload.tax = values.tax;
            payload.email = values.email;
            payload.invoicetype = values.invoicetype;
            payload.csttype = values.csttype;
            payload.address = values.address;
            payload.addressen = values.addressen;
            payload.recaddress = values.recaddress;
            payload.url = values.url;


            payload.industry = R.isNil(values.industry) ? null : values.industry[0];
            payload.mainproduct = R.isNil(values.industry) ? null : values.industry[1];


            payload.subindustry = values.subindustry;
            payload.settlement = values.settlement;
            payload.lastexports = values.lastexports;
            payload.premonthexportamount = values.premonthexportamount;



            payload.entrust = values.entrust;


            payload.exportcountry = values.exportcountry;
            payload.fkmanager = values.fkmanager;

            payload.capital = values.capital;
            payload.capitalcurrency = values.capitalcurrency;
            payload.registerdate = values.registerdate ? values.registerdate.format(Constants.DATEFORMAT) : "";
            payload.bussiregno = values.bussiregno;
            payload.taxpayerid = values.taxpayerid;
            payload.orgcode = values.orgcode;
            payload.customsregno = values.customsregno;
            payload.entperson = values.entperson;
            payload.businessType = this.props.businessType ? this.props.businessType : dataSource.businessType;
            //payload.autoSync = values.autoSync;

            //工商信息
            if (!payload.id) {   //初次新增，可能调用了同步接口
                const { ldData } = this.state;
                payload.capital = ldData.regcap;//注册资本
                payload.capitalcurrency = CurencyConstants.CURRENCY[ldData.regcapcur];//注册资本币种
                payload.registerdate = ldData.esdate;//成立日期
                payload.taxpayerid = ldData.shxydm;//纳税人识别码
                payload.orgcode = ldData.orgid;//组织机构代码
                payload.customsregno = ldData.hgzcbm;//海关注册登记号码
                payload.entperson = ldData.frdb;//企业法人
                payload.bussiregno = ldData.regno;//工商注册号
            }

            payload.taxId = values.taxId;
            payload.onSuccess = () => {
                onSuccess();
            };

            if (changeStatus == 2) {
                payload.status = changeStatus;
            }

            if (dataSource.businessType === "2" && changeStatus != null) {
                functionname = "updateMpCustomerBase";
                payload.status = Constants.NUMBER_FOUR;
            }


            dispatch({
                type: 'customerManage/' + functionname,
                payload: payload
            });


        })
    };



    render() {
        const { getFieldDecorator, getFieldValue } = this.props.form;
        let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
        let lesseeExt = this.props.lesseeExt ? this.props.lesseeExt : {};
        let formItemLayout = {
            labelCol: { xs: { span: 24 }, sm: { span: 9 } },
            wrapperCol: { xs: { span: 24 }, sm: { span: 10 } }
        };

        const formItemLayout2 = {
            labelCol: { span: 5 },
            wrapperCol: { span: 18 }
        };

        const formItemLayout3 = {
            labelCol: { sm: { span: 7 } },
            wrapperCol: { sm: { span: 16 } }
        };

        let ldFlag = !dataSource.id && lesseeExt.serviceLevel > 1 && moment().format(Constants.DATEFORMAT) < lesseeExt.expiredDate && lesseeExt.ldRequestBalance > 0; //是否出现企业自动同步按钮

        let csttypeForm =
            <Col span={12}>
                <FormItem {...formItemLayout} label="客户类型" hasFeedback>
                    {getFieldDecorator('csttype', {
                        initialValue: dataSource.csttype
                    })(
                        <Select style={{ width: '100%' }} disabled={true}>
                            <Select.Option value="0" key="0">普通客户</Select.Option>
                            <Select.Option value="1" key="1">会员客户</Select.Option>
                        </Select>
                        )}
                </FormItem>
            </Col>;

        let industry = [];
        R.isNil(dataSource.industry) ? "" : industry.push(dataSource.industry);
        R.isNil(dataSource.mainproduct) ? "" : industry.push(dataSource.mainproduct);

        return (
            <Form>
                <Tabs tabPosition={'top'}>
                    <TabPane tab="企业信息" key="1">
                        <Row>
                            <Col span={16} style={{ width: ldFlag ? '65.4%' : '91.66666667%' }}>
                                <FormItem
                                    {...ldFlag ? formItemLayout3 : formItemLayout2}
                                    label="客户名称(中文)"
                                    hasFeedback
                                >
                                    {getFieldDecorator('companyname', {
                                        rules: [{
                                            required: true, message: '请填写客户名称(中文)！',
                                        }],
                                        initialValue: dataSource.companyname

                                    })(
                                        <Input disabled={this.props.disabled} maxLength="50" />
                                        )}
                                </FormItem>
                            </Col>
                            {ldFlag ?
                                <Col span={6} style={{ paddingLeft: '6%' }}>
                                    <Button type="primary" onClick={this.autoSync.bind(this)}>一键同步企业信息</Button>
                                    <Tooltip placement="bottomLeft" arrowPointAtCenter autoAdjustOverflow
                                        title={
                                            <div>
                                                <div >{`1、您当前使用的是进阶版本，可以直接通过接口同步客户的企业信息，版本功能过期日：${lesseeExt.expiredDate}, 剩余可调用次数：${lesseeExt.ldRequestBalance}。`}</div>
                                                <div>2、请确保客户名称输入准确，否则信息将可能无法同步成功。</div>
                                                <div>3、每次点击按钮则视为调用了一次接口，24小时内同一客户名称可多次同步，若无法成功同步信息则不计算调用次数，同时请人工录入。</div>
                                            </div>
                                        }
                                    >
                                        <Icon style={{ marginLeft: 10, fontSize: 16, color: '#08c' }} type="question-circle-o" />
                                    </Tooltip>
                                </Col> : ""}
                        </Row>
                        {this.props.businessType === "2" ? ""
                            :
                            <Row>
                                <Col span={22}>
                                    <FormItem
                                        {...formItemLayout2}
                                        label="客户名称(英文)"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('companynameen', {
                                            rules: [{
                                                required: true, message: '请填写客户名称(英文)！',
                                            }],
                                            initialValue: dataSource.companynameen
                                        })(
                                            <Input disabled={this.props.disabled} maxLength="200" />
                                            )}
                                    </FormItem>
                                </Col>
                            </Row>
                        }
                        {this.props.businessType === "2" ? ""
                            :
                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="客户简称"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('shortname', {
                                            rules: [{
                                                required: true, message: '请填写客户简称！',
                                            }],
                                            initialValue: dataSource.shortname
                                        })(
                                            <Input disabled={this.props.disabled} maxLength="30"/>
                                            )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="是否查询企业信用"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('ischeckinfo', {
                                            rules: [{
                                                required: true, message: '请选择是否查询企业信用！',
                                            }],
                                            initialValue: dataSource.ischeckinfo
                                        })(
                                            <RadioGroup disabled={this.props.disabled}>
                                                <Radio value={"1"}>是</Radio>
                                                <Radio value={"2"}>否</Radio>
                                            </RadioGroup>
                                            )}
                                    </FormItem>
                                </Col>
                            </Row>
                        }

                        <Row>
                            <Col span={12}>
                                <FormItem
                                    {...formItemLayout}
                                    label="企业类型"
                                    hasFeedback
                                >
                                    {getFieldDecorator('companytype', {
                                        rules: [{
                                            required: true, message: '请选择企业类型！'
                                        }],
                                        initialValue: dataSource.companytype
                                    })(
                                        <BizParams sprCode={"cstType"} style={{ width: '100%' }} blank={true} disabled={this.props.disabled} />
                                        )}
                                </FormItem>
                            </Col>
                            {this.props.businessType === "2" ? ""
                                :
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="经营模式"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('businessmodel', {
                                            rules: [{
                                                required: true, message: '请选择经营模式！',
                                            }],
                                            initialValue: R.isNil(dataSource.businessmodel) ? "" : dataSource.businessmodel + ""
                                        })(
                                            <BizParams sprCode={"businessModel"} style={{ width: '100%' }} blank={true} disabled={this.props.disabled} />
                                            )}
                                    </FormItem>
                                </Col>
                            }
                        </Row>
                        <Row>
                            <Col span={12}>
                                <FormItem
                                    {...formItemLayout}
                                    label="移动电话"
                                    hasFeedback
                                >
                                    {getFieldDecorator('mobile', {
                                        rules: [{
                                            required: true, message: '请填写移动电话！',
                                            pattern: Validator.mobile, message: '请输入正确的移动电话',
                                        }],
                                        initialValue: dataSource.mobile
                                    })(
                                        <Input disabled={this.props.disabled} maxLength="20"/>
                                        )}
                                </FormItem>
                            </Col>
                            {this.props.businessType === "2" ? ""
                                :
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="固定电话"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('telephone', {
                                            rules: [{
                                                required: true, message: '请填写固定电话！',
                                                pattern: Validator.phone, message: '请填写正确的固定电话',

                                            }],
                                            initialValue: dataSource.telephone
                                        })(
                                            <Input disabled={this.props.disabled} maxLength="20"/>
                                            )}
                                    </FormItem>
                                </Col>
                            }
                        </Row>
                        <Row>
                            <Col span={12}>
                                <FormItem
                                    {...formItemLayout}
                                    label="邮箱（E-mail）"
                                    hasFeedback
                                >
                                    {getFieldDecorator('email', {
                                        rules: [{
                                            required: true, message: '请填写邮箱！',
                                            type: 'email', message: '请填写正确的邮箱',
                                        }],
                                        initialValue: dataSource.email
                                    })(
                                        <Input disabled={this.props.disabled} maxLength="30"/>
                                        )}
                                </FormItem>
                            </Col>
                            {this.props.businessType === "2" ? ""
                                :
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="传真"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('tax', {
                                            rules: [{
                                                required: false, message: '请填写传真！',
                                                pattern: Validator.fax, message: '请填写正确的传真',
                                            }],
                                            initialValue: dataSource.tax
                                        })(
                                            <Input disabled={this.props.disabled} maxLength="20"/>
                                            )}
                                    </FormItem>
                                </Col>
                            }
                        </Row>
                        {this.props.businessType === "2" ? ""
                            :
                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="服务模式"
                                        hasFeedback
                                    >

                                        {getFieldDecorator('invoicetype', {
                                            rules: [{
                                                required: true, message: '请选择服务模式'
                                            }],
                                            initialValue: R.isNil(dataSource.invoicetype) ? "1" : dataSource.invoicetype
                                        })(
                                            <BizParams sprCode={"invoiceType"} style={{ width: '100%' }} disabled={this.props.disabled} />
                                            )}{this.handleCustomer() ? "" : <span style={{ color: 'red', marginLeft: 5, fontSize: 13, }}>(两者计算开票金额的方式不一致，外综需工厂到税局备案，请慎重选择)</span>}
                                    </FormItem>
                                </Col>
                                {this.handleCustomer() ? csttypeForm : ""}
                            </Row>
                        }
                        {this.props.businessType === "2" ? ""
                            :
                            <Row>
                                <Col span={22}>
                                    <FormItem
                                        {...formItemLayout2}
                                        label="公司网址"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('url', {
                                            initialValue: dataSource.url
                                        })(
                                            <Input disabled={this.props.disabled} maxLength="100"/>
                                            )}
                                    </FormItem>
                                </Col>
                            </Row>
                        }
                        <Row>
                            <Col span={22}>
                                <FormItem
                                    {...formItemLayout2}
                                    label="公司地址(中文)"
                                    hasFeedback
                                >
                                    {getFieldDecorator('address', {
                                        rules: [{
                                            required: true, message: '请填写公司地址(中文)！',
                                        }],
                                        initialValue: dataSource.address
                                    })(
                                        <Input disabled={this.props.disabled} maxLength="100"/>
                                        )}
                                </FormItem>
                            </Col>
                        </Row>
                        {this.props.businessType === "2" ? ""
                            :
                            <Row>
                                <Col span={22}>
                                    <FormItem
                                        {...formItemLayout2}
                                        label="公司地址(英文)"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('addressen', {
                                            rules: [{
                                                required: dataSource.csttype === "1", message: '请填写公司地址(英文)！',
                                            }],
                                            initialValue: dataSource.addressen
                                        })(
                                            <Input disabled={this.props.disabled} maxLength="300"/>
                                            )}
                                    </FormItem>
                                </Col>
                            </Row>
                        }
                        <Row>
                            <Col span={22}>
                                <FormItem
                                    {...formItemLayout2}
                                    label="收件地址"
                                    hasFeedback
                                >
                                    {getFieldDecorator('recaddress', {
                                        rules: [{
                                            required: true, message: '请填写收件地址！',
                                        }],
                                        initialValue: dataSource.recaddress
                                    })(
                                        <Input disabled={this.props.disabled} maxLength="100"/>
                                        )}
                                </FormItem>
                            </Col>
                        </Row>
                        {/* 以下的<Row>为龙盾工商接口同步专用，出现条件1.首次保存客户，非二次编辑2.当前在租户级别至少是"进阶版"，租户版本仍在服务有效期内，同步次数有余 */}
                        {/*!dataSource.id && lesseeExt.serviceLevel > 1 && moment().format(Constants.DATEFORMAT) < lesseeExt.expiredDate && lesseeExt.ldRequestBalance > 0 ?
                            <div>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="是否自动同步工商信息"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('autoSync', {
                                                rules: [{
                                                    required: true, message: '请选择是否自动同步工商信息！',
                                                }],
                                                initialValue: "1"
                                            })(
                                                <RadioGroup disabled={this.props.disabled}>
                                                    <Radio value={"1"}>是</Radio>
                                                    <Radio value={"0"}>否</Radio>
                                                </RadioGroup>
                                                )}
                                        </FormItem>
                                    </Col>
                                    {/* <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="纳税人识别码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('taxId', {
                                                rules: [{
                                                    required: getFieldValue("autoSync") === "1" ? true : false, message: '请填写纳税人识别码！',
                                                }],
                                                initialValue: undefined
                                            })(
                                                <Input disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                    </Col> }
                                </Row>
                                <div>
                                    <div style={{ color: 'red' }}>{`1、您当前使用的是进阶版本，可以直接通过接口同步当前客户的工商信息，版本功能过期日：${lesseeExt.expiredDate}, 剩余可调用次数：${lesseeExt.ldRequestBalance}`}</div>
                                    <div style={{ color: 'red' }}>2、每次创建且保存客户时，选择自动同步则视为调用了一次接口，删除名称相同的客户又重新录入也算一次，同步失败则不算(失败可通过编辑人工录入)。</div>
                                    <div style={{ color: 'red' }}>3、请确保客户名称的正确性，否则可能同步失败。</div>
                                    <div style={{ color: 'red' }}>4、如果您需要获取更多的企业信息或者资信报告，请咨询购买大数据版本系统，客服电话4001892323咨询。</div>
                                    <div style={{ color: 'red' }}>5、登录洲博通官网www.zbtservice.com, 更可购买境外买家信用报告，助力企业规避外贸风险。</div>
                                </div>
                            </div> : ""
                        */}
                    </TabPane>
                </Tabs>

                {this.state.type == "edit" ?
                    <span>
                        <Tabs tabPosition={'top'} >
                            <TabPane tab="工商注册信息" key="2">
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="注册资本"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('capital', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写注册资本！',
                                                }],
                                                initialValue: dataSource.capital
                                            })(
                                                <InputNumber style={{ width: 150 }} disabled={this.props.disabled} maxLength="18"/>
                                                )}
                                            （万）
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="注册资本币种"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('capitalcurrency', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请选择注册资本币种！',
                                                }],
                                                initialValue: dataSource.capitalcurrency
                                            })(
                                                <CurrencySelect disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="成立日期"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('registerdate', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写成立日期！',
                                                }],
                                                initialValue: dataSource.registerdate == undefined ? '' : moment(dataSource.registerdate, Constants.DATEFORMAT)
                                            })(
                                                <DatePicker style={{ width: 150 }} disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="工商注册号"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('bussiregno', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写工商注册号！',
                                                }],
                                                initialValue: dataSource.bussiregno
                                            })(
                                                <Input disabled={this.props.disabled} maxLength="20"/>
                                                )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="纳税人识别码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('taxpayerid', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写纳税人识别码！',
                                                }],
                                                initialValue: dataSource.taxpayerid
                                            })(
                                                <Input disabled={this.props.disabled} maxLength="20"/>
                                                )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="组织机构代码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('orgcode', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写组织机构代码！',
                                                }],
                                                initialValue: dataSource.orgcode
                                            })(
                                                <Input disabled={this.props.disabled} maxLength="20"/>
                                                )}
                                        </FormItem>
                                    </Col>

                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="海关注册登记号码"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('customsregno', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写海关注册登记号码！',
                                                }],
                                                initialValue: dataSource.customsregno
                                            })(
                                                <Input disabled={this.props.disabled} maxLength="20"/>
                                                )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="企业法人"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('entperson', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写企业法人！',
                                                }],
                                                initialValue: dataSource.entperson
                                            })(
                                                <Input disabled={this.props.disabled} maxLength="30"/>
                                                )}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </TabPane>
                        </Tabs>
                        <Tabs tabPosition={'top'} >
                            <TabPane tab="营业信息" key="3">
                                <Row>
                                    <Col span={22}>
                                        <FormItem
                                            {...formItemLayout2}
                                            label="主营产品  "
                                            hasFeedback
                                        >
                                            {getFieldDecorator('industry', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写主营产品！',
                                                }],
                                                initialValue: industry
                                            })(
                                                <IndustrySelect disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                    </Col>

                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="主要收汇方式"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('settlement', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请选择主要收汇方式！',
                                                }],
                                                initialValue: dataSource.settlement
                                            })(
                                                <BizParams sprCode={"settlement"} style={{ width: '100%' }} blank={true} disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="年销售额"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('lastexports', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写年销售额！',
                                                }],
                                                initialValue: dataSource.lastexports
                                            })(
                                                <InputNumber min={0} style={{ width: 150 }} disabled={this.props.disabled} maxLength="18" />
                                                )}
                                            （万美元）
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="预计每月出口额"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('premonthexportamount', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写预计每月出口额！',
                                                }],
                                                initialValue: dataSource.premonthexportamount
                                            })(
                                                <InputNumber min={0} style={{ width: 150 }} disabled={this.props.disabled} maxLength="18" />
                                                )}
                                            （万美元）
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="预计每年委托出口额"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('entrust', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写预计每年委托出口额！',
                                                }],
                                                initialValue: dataSource.entrust
                                            })(
                                                <InputNumber min={0} style={{ width: 150 }} disabled={this.props.disabled} maxLength="18" />
                                                )}
                                            （万美元）
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="主要出口国家/地区"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('exportcountry', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请选择主要出口国家/地区！',
                                                }],
                                                initialValue: dataSource.exportcountry
                                            })(
                                                <Input disabled={this.props.disabled} maxLength="50" />
                                                )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="行业经营年限"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('subindustry', {
                                                rules: [{
                                                    required: this.props.businessType != "2" ? true : false, message: '请填写主要行业经营年限！',
                                                }],
                                                initialValue: dataSource.subindustry
                                            })(
                                                <InputNumber min={0} style={{ width: 150 }} disabled={this.props.disabled} maxLength="10"/>
                                                )}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </TabPane>
                        </Tabs>
                    </span>
                    : ""}

                {this.state.type == "edit" && !R.equals(dataSource.csttype, "2") ?
                    <div>
                        <Tabs tabPosition={'top'}>
                            <TabPane tab="人员分配" key="3">
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="风控经理分配"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('fkmanager', {
                                                rules: [{
                                                    required: true, message: '请选择风控经理分配！',
                                                }],
                                                initialValue: dataSource.fkmanager
                                            })(
                                                <ManageSelect sprCode={"fkmanager"} style={{ width: '100%' }} blank={true}
                                                    disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                        {/*<Select style={{width: 150}} disabled={this.props.disabled} >*/}
                                        {/*{*/}
                                        {/*R.isNil(fkmanager) || R.isEmpty(fkmanager)  ? <Option value=""> </Option>*/}
                                        {/*:*/}
                                        {/*(fkmanager).map(item => {*/}
                                        {/*return (<Option value={item.userId} key={item.userId}>{item.username}</Option>);*/}
                                        {/*})*/}
                                        {/*}*/}
                                        {/*</Select>*/}
                                    </Col>
                                </Row>
                            </TabPane>
                        </Tabs>
                        <RightBox resource={RightContacts.CUSTOMER.CUSTOMER_PERSONNEL_ASSIGNMENT}>
                            <Tabs tabPosition={'top'}>
                                <TabPane tab="其他人员分配" key="4">

                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="业务经理分配"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('manager', {
                                                rules: [{
                                                    required: false, message: '请选择业务经理！',
                                                }],
                                                initialValue: dataSource.manager
                                            })(
                                                <ManageSelect sprCode={"ywmanager"} style={{ width: '100%' }} blank={true}
                                                    disabled={this.props.disabled} />
                                                )}
                                        </FormItem>
                                    </Col>
                                </TabPane>
                            </Tabs>
                        </RightBox>
                        <RightBox resource={RightContacts.CUSTOMER.CUSTOMER_ADD_FACTORYCUSTOMER}>
                            <Tabs tabPosition={'top'}>
                                <TabPane tab="开设工厂客户" key="4">
                                    <Col span={12}>
                                        <Popconfirm placement="leftTop" title={'是否确定开设工厂用户账号？'}
                                            onConfirm={() => {
                                                this.props.dispatch({
                                                    type: 'customerManage/createFactotyCustomer',
                                                    payload: {
                                                        customerId: dataSource.id,
                                                        onSuccess: () => {
                                                            this.props.dispatch({ type: 'customerManage/getCustomerById', payload: { id: dataSource.id, isApproval: true } });
                                                        },
                                                        onFail: () => {
                                                            message.error("开设工厂用户账号失败！");
                                                        }
                                                    }
                                                })
                                            }} okText="是" cancelText="否">
                                            <Button type="primary"
                                                icon="className"
                                                size={'default'}
                                                disabled={this.props.factoryUser ? true : false}>开设工厂用户</Button>
                                        </Popconfirm>
                                    </Col>
                                </TabPane>
                            </Tabs>
                        </RightBox>
                        {R.isNil(this.props.blacklist) ? "" :
                            <Tabs tabPosition={'top'}>
                                <TabPane tab="黑名单" key="4">
                                    <Row>
                                        <Col span={12}>
                                            <FormItem
                                                {...formItemLayout2}
                                                label="黑名单备注"
                                                hasFeedback
                                            >
                                                {getFieldDecorator('blacklistMemo', {
                                                    rules: [{
                                                        required: false, message: '请黑名单备注',
                                                    }],
                                                    initialValue: dataSource.blacklistMemo
                                                })(
                                                    <Input.TextArea disabled={dataSource.isblacklist ? true : false}
                                                        maxLength="200" autosize={true} />
                                                    )}
                                            </FormItem>
                                        </Col>
                                        {(R.isEmpty(dataSource.isblacklist) || dataSource.isblacklist) ?
                                            "" :
                                            <Col span={12}>
                                                <RightBox resource={RightContacts.CUSTOMER.CUSTOMER_BLACKLIST_ADD}>
                                                    <Button type="primary" icon="add"
                                                        onClick={this.handleAddBlacklist.bind(this, dataSource.id)}>加入黑名单</Button>
                                                </RightBox>
                                            </Col>
                                        }
                                    </Row>
                                </TabPane>
                            </Tabs>
                        }
                    </div>
                    : ""}

            </Form>
        )
    }


})


// WEBPACK FOOTER //
// ./public/src/components/customer/components/EditCustomer.js